let { classifysModel } = require('../models/classifysModels')
const { productsModel } = require('../models/productsModels')
//新增保险项目
module.exports.addClassifys = async function (data) {
    return await classifysModel.create(data)
}
//获取  渲染
module.exports.getClassifys = async function (data) {
    let { currentPage, pageSize } = data;
    let total = await classifysModel.countDocuments({ delete: false });
    let pages = Math.ceil(total / pageSize);
    let classifysData = await classifysModel.find(
        { delete: false }
    ).populate('productsId').limit(pageSize - 0)
        .skip((currentPage - 1) * pageSize);
    return { classifysData, pages, total }
}
//删除
module.exports.deleteClassifys = async function (data) {
    return await classifysModel.updateOne(data, { delete: true })
}
//修改
module.exports.modifyClassifys = async function (data) {
    let { id, myrename } = data;
    return await classifysModel.updateOne({ _id: id }, { name: myrename })
}

//查询保险种类是否有内容
module.exports.deleteGetClassifys = async function (data) {
    return await classifysModel.find(data).populate('productsId');
}